home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-12 | 2.1 KB | 48 lines | [TEXT/R*ch] |
- Trapping Non-Trap Vector Calls The Debugger has certain limitations in its
- ability to trace A-Line traps and such. As an example, suppose we’re interested
- in breaking on calls to CacheFlush. It’s a trap vector which is usually
- referenced by a JSR ([xx]) instead of the usual A-Line Trap vector. Because it
- doesn’t go through the normal A-line dispatcher, we can’t break on references to
- it with the Trap Intercept mechanism. Here’s some example code that creates a
- dummy procedure in an application, and an initialization proc that patches the
- low-memory trap vector so that it points to the dummy procedure. I modify the
- dummy procedure to make it a JMP to the original value of the low memory vector
- [Remember, this is for debugging, not for shipping code. Shipping code should
- generally not modify code it’s about to execute – Ed stb]. Finally, the doPatch
- proc undoes the patch and restores the system to its previous state. To use this,
- set a breakpoint at my_doPatch_Proc. When you drop into your debugger, look at
- the stack to see who’s calling. After some looking, you can automate the process
- by observing where the interesting return addresses are on the stack with an
- action clause (such as the one shown here) that would list them in the -Notes-
- window: ?ra := (ra7)^; { return addr is contents of A7 }
-
- { In the next line we check PC for an address in the Quadra 900 ROM }
- if ?pc = 40887824 then ?ra := (ra7+#46+#28)^-2; { # = decimal } writeln(?ra:ProcPtr); { display the address as a proc name + offset }
- resume;
-
- procedure my_doPatch_Proc; { make it at least 6 bytes long }
- begin
- end;
-
- procedure doPatch(doit:Boolean);
- CONST jCacheFlush = $6f4;
- type jmpL = record opc:integer; addr:Longint; end;
- VAR
- q:^jmpL;
- p:^Longint;
- begin
- p := pointer(jCacheFlush); {$06F4 is the low-mem global jCacheFlush}
- q := @my_doPatch_Proc;
- if doit then begin
- with q^ do begin
- opc := $4EF9; {JMP.L}
- addr := p^;
- end;
- p^ := Ord(q);
- end
- else begin
- p^ := q^.addr; { undo patch }
- end;
- end;
- – Steve Jasik, Menlo Park, CA
-